package com.three_learn.star.system.controller;


import com.three_learn.star.system.po.DTO.SysUserDTO;
import com.three_learn.star.system.po.VO.SysUserVO;
import com.three_learn.star.system.po.query.UserQuery;
import com.three_learn.star.system.service.ISysUserService;
import com.three_learn.star.project.vo.JsonVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 用户信息表 前端控制器
 * </p>
 *
 * @author KO
 * @since 2024-12-07
 */
@RestController
@RequestMapping("system/sys-user")
public class SysUserController {

    @Resource
    ISysUserService sysUserService;

    /**
     * 分页查找用户
     * @param page 第几页
     * @param pageSize 每页显示多少条
     * @return pageSize条的数组
     */
    @GetMapping("list")
    public JsonVO<List<SysUserVO>> getUserList(@RequestParam("page") Integer page, @RequestParam("pageSize") Integer pageSize) {
        return JsonVO.success(sysUserService.queryAll(page,pageSize));

    };

    /**
     * 根据查询条件和分页条件进行分页
     * @param page 第几页
     * @param pageSize 每页显示多少条

     * @return
     */
    @GetMapping("/queryList")
    public JsonVO<List<SysUserVO>> getUserList1(@RequestParam("page") Integer page, @RequestParam("pageSize") Integer pageSize, UserQuery userQuery) {
        return JsonVO.success(sysUserService.queryAll1(page,pageSize,userQuery));
    };


    /**
     * 获取单个用户信息
     *
     * return 用户VO对象
     */
    @GetMapping("/getUserInfo")
    public JsonVO<SysUserVO>  getUserInfo(Long id){
        SysUserVO sysUserVO =sysUserService.getUserInfo(id);
        return JsonVO.success(sysUserVO);
    } ;
    /**
     * 修改单个用户信息
     *
     * return
     */
    @PutMapping("/updateUserInfo")
    public JsonVO<Boolean> updateUserInfo(@RequestBody SysUserDTO sysUserDTO){
        sysUserService.updateById(sysUserDTO);
        return JsonVO.success(true);
    } ;;
    /**
     * 新增用户信息
     *
     * return 新增用户结果
     */
    @PostMapping("/add")
    public JsonVO<Boolean> addUserInfo(@RequestBody SysUserDTO sysUserDTO){
        sysUserService.addUserInfo(sysUserDTO);
        return JsonVO.success(true);
    } ;
    /**
     * 删除用户信息
     *
     * return 删除用户结果
     */
    @DeleteMapping("/deleteUserList/{ids}")
    public JsonVO<Boolean> deleteUserInfo(@PathVariable("ids") ArrayList<Long> ids){
        sysUserService.deleteByIds(ids);
        return JsonVO.success(true);
    } ;

}

